package com.boho.estates.usual.dao;
import java.sql.Connection;

import cn.boho.framework.po.CQuery;
import cn.boho.framework.po.CQueryFactoryTool;
import cn.boho.framework.po.ComboPager;
import cn.boho.framework.po.DAO;
import cn.boho.framework.po.DynaBeanMap;
import cn.boho.framework.po.Pager;
public class TCheckInfoDao extends DAO{

	/**
	* 分页查询所有【盘点信息:T_CHECK_INFO】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-12-04
	* @author 许福辉
	*
	*/
	public static ComboPager queryTCheckInfoByPager(Connection con,Pager pager,String check_no,String check_status,String begin_date,String end_date, String departIds)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_CHECK_INFO where IS_VALID=1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		int m=0;
		if(check_no != null && check_no.toString().length() > 0){
			sql.append(" and CHECK_NO like ?");
			query.setString(++m, "%"+check_no+"%");
		}
		if(check_status != null && check_status.toString().length() > 0){
			sql.append(" and CHAGE_STATUS = ?");
			query.setString(++m, check_status);
		}
		if((begin_date != null && begin_date.toString().length() > 0)&&(end_date != null && end_date.toString().length() > 0)){
			sql.append(" and CHANGE_BEGIN_DATE >=?  and CHANGE_BEGIN_DATE<=? ");
			query.setString(++m, begin_date);
			query.setString(++m, end_date);
		}
		sql.append(" and DEPARTMENT_NO in (").append(departIds).append(")");
		sql.append(" order by CHANGE_BEGIN_DATE desc");
		query.setCommand(sql.toString());
		return query.getDynaBeanMapComboPager("T_CHECK_INFO", pager,con);
	}

	/**
	* 根据CHECK_NO【ID:CHECK_NO|】获得信息
	* @param con
	* @param id CHECK_NO
	* @return
	* @throws Exception
	* @date 2011-12-04
	* @author 许福辉
	*
	*/
	public static DynaBeanMap getTCheckInfoByCheckNO(Connection con,String check_no)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_CHECK_INFO where  CHECK_NO=? and IS_VALID=1  order by CREATE_DATE desc");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setString(1, check_no);
		dynaBeanMap = query.getDynaBeanMap("T_CHECK_INFO", con);
		return dynaBeanMap;
	}

	/**
	* 分页查询所有【盘点明细:T_CHECK_INFO_DETAIL】信息
	* @param con
	* @param pager
	* @return
	* @throws Exception
	* @date 2011-12-04
	* @author 许福辉
	*
	*/
	public static ComboPager queryTCheckInfoDetailByPager(Connection con,Pager pager,String check_no,String bracode,String is_check,String dempStr)throws Exception{
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_CHECK_INFO_DETAIL where IS_VALID=1");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		int m=0;
		if(check_no != null && check_no.toString().length() > 0){
			sql.append(" and CHECK_NO = ?");
			query.setString(++m, check_no);
		}
		if(bracode != null && bracode.toString().length() > 0){
			sql.append(" and BARCODE like ?");
			query.setString(++m, "%"+bracode+"%");
		}
		if(is_check != null && is_check.toString().length() > 0){
			sql.append(" and IS_CHECK = ?");
			query.setString(++m, is_check);
		}
		sql.append(" and DEPARTMENT_NAME in (").append(dempStr).append(")");
		sql.append("  order by BARCODE");
		query.setCommand(sql.toString());
		logger.debug("TCheckInfoDao.queryTCheckInfoDetailByPager() SQL->"+query.getCommand());
		return query.getDynaBeanMapComboPager("T_CHECK_INFO_DETAIL", pager,con);
	}

	/**
	* 根据主键【ID:ID|】获得信息
	* @param con
	* @param id ID
	* @return
	* @throws Exception
	* @date 2011-12-04
	* @author 许福辉
	*
	*/
	public static DynaBeanMap getTCheckInfoByPk(Connection con,java.lang.Integer id)throws Exception{
		DynaBeanMap dynaBeanMap = null;
		StringBuffer sql = new StringBuffer();
		sql.append("select * from T_CHECK_INFO where  ID=?  order by CREATE_DATE desc");
		CQuery query = CQueryFactoryTool.createFactory().createCQuery();
		query.setCommand(sql.toString());
		query.setInt(1,id);
		dynaBeanMap = query.getDynaBeanMap("T_CHECK_INFO", con);
		return dynaBeanMap;
	}

}
